local BuffNameFloatView = class("BuffNameFloatView",function() return display.newNode() end )

local NodePool = custom.NodePool:getInstance()

function BuffNameFloatView.create()
    return NodePool:getByKey("BuffNameFloatView") or BuffNameFloatView.new()
end

function BuffNameFloatView:ctor()
    local node = cc.CSLoader:createNode(Res.BattleBuffUsefulEffect)
    display.setCascadeOpacityEnabled(node,true)

    local teamTextView = node:findChild("team/name")
    teamTextView:setVisible(false)
    self._teamTextView = teamTextView
    local foeTextView = node:findChild("foe/name")
    foeTextView:setVisible(false)
    self._foeTextView = foeTextView
    self._node = node
    self:addChild(node)
end

function BuffNameFloatView:play(isSelfTeam,name)

    local teamTextView = self._teamTextView
    local foeTextView = self._foeTextView
    
    teamTextView:setVisible(false)
    foeTextView:setVisible(false)

    local displayView = isSelfTeam and teamTextView or foeTextView
    displayView:setVisible(true)
    displayView:setString(name)


    local node = self._node
    node:setVisible(true)

    local timeline = node:getTimeline()
    timeline:gotoFrameAndPlay(0,false)
    timeline:setLastFrameCallFunc(function()
        if not cc.isDead(node) then
            node:setVisible(false)
        end
        if not cc.isDead(self) then
            NodePool:put(self,"BuffNameFloatView")
            self:removeFromParent(false)
        end
    end)
    return timeline:getDuration()
end


return BuffNameFloatView